<template>
  <div class="dashboard">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-number">{{ stats.users }}</div>
            <div class="stat-label">总用户数</div>
          </div>
          <i class="el-icon-user stat-icon"></i>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-number">{{ stats.orders }}</div>
            <div class="stat-label">总订单数</div>
          </div>
          <i class="el-icon-s-order stat-icon"></i>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-number">{{ stats.revenue }}</div>
            <div class="stat-label">总收入</div>
          </div>
          <i class="el-icon-money stat-icon"></i>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-number">{{ stats.growth }}</div>
            <div class="stat-label">增长率</div>
          </div>
          <i class="el-icon-trend-charts stat-icon"></i>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" style="margin-top: 20px;">
      <el-col :span="12">
        <el-card>
          <template #header>
            <span>最近活动</span>
          </template>
          <el-timeline>
            <el-timeline-item
              v-for="(activity, index) in recentActivities"
              :key="index"
              :timestamp="activity.time"
              :type="activity.type"
            >
              {{ activity.content }}
            </el-timeline-item>
          </el-timeline>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card>
          <template #header>
            <span>快速操作</span>
          </template>
          <el-button-group style="width: 100%;">
            <el-button type="primary" @click="quickAction('addUser')">新增用户</el-button>
            <el-button type="success" @click="quickAction('createOrder')">创建订单</el-button>
            <el-button type="warning" @click="quickAction('exportData')">导出数据</el-button>
          </el-button-group>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'Dashboard',
  data() {
    return {
      stats: {
        users: 1234,
        orders: 5678,
        revenue: '¥89,123',
        growth: '+12.5%'
      },
      recentActivities: [
        { time: '2024-01-15 10:30', content: '新用户注册', type: 'primary' },
        { time: '2024-01-15 09:15', content: '订单完成', type: 'success' },
        { time: '2024-01-15 08:45', content: '系统更新', type: 'info' },
        { time: '2024-01-14 18:20', content: '数据备份', type: 'warning' }
      ]
    }
  },
  methods: {
    quickAction(action) {
      this.$message.success(`执行操作: ${action}`)
    }
  }
}
</script>

<style scoped>
.dashboard { padding: 20px; }
.stat-card { position: relative; overflow: hidden; }
.stat-content { text-align: center; }
.stat-number { font-size: 24px; font-weight: bold; color: #409EFF; }
.stat-label { margin-top: 8px; color: #666; }
.stat-icon { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); font-size: 48px; color: #f0f0f0; }
</style>
